package 面向对象.TestEight;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

/**
 * @author IT_Jay
 * @date 2021/11/24 20:04
 */

public class JFrame3 extends JFrame {

    static Choice choice;
    static JTextArea classArea;
    static String content1 = "我是面向对象!";
    static String content2 = "我是算法语言基础!";
    static String content3 = "我是数据库!";
    static String content4 = "我是数据结构!";
    static String[] contents = {content1,content2,content3,content4};

    public static void main(String[] args) {
        JFrame3 jf = new JFrame3();
        jf.init();
    }

    public void init() {
        JPanel panel = new JPanel(new BorderLayout());
        choice = new Choice();
        choice.add("面向对象");
        choice.add("算法语言基础");
        choice.add("数据库");
        choice.add("数据结构");
        choice.getSelectedItem();
        panel.add(choice, BorderLayout.NORTH);

        classArea = new JTextArea();
        classArea.setVisible(true);
        classArea.setText(content1);
        panel.add(classArea,BorderLayout.CENTER);

        JFrame frame =new JFrame();
        frame.setSize(300,300);
        frame.setTitle("课程介绍");
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(panel);
        addListener();

    }

    private void addListener() {
        choice.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                classArea.setText(contents[choice.getSelectedIndex()]);
            }
        });
    }

}
